#include <iostream>
using namespace std;

class Chair{
public:
   virtual void sitdown()=0;
   virtual ~Chair()=default;
};
class ChineseChair:public Chair{
public:
    virtual void sitdown(){
        cout<<"chinesechir"<<endl;
    }
    virtual ~ChineseChair()=default;
};
class AmericanChair:public Chair{
public:
    virtual void sitdown(){
        cout<<"AmericanChair"<<endl;
    }
    virtual ~AmericanChair()=default;
};
class Table{
public:
   virtual void up()=0;
   virtual ~Table()=default;
};
class ChineseTable:public Table{
public:
    virtual void up(){
        cout<<"ChineseTableup"<<endl;
    }
    virtual ~ChineseTable()=default;
};
class AmericanTable:public Table{
    virtual void up(){
        cout<<"AmericanTableup"<<endl;
    }
    virtual ~AmericanTable()=default;
};
class AbstractFactory{
public:
   virtual Chair* creatChair()=0;
   virtual Table* createTable()=0;
};
class ChineseFactory:public AbstractFactory{
public:
    virtual Chair* creatChair(){
        return new ChineseChair;
    }
    virtual Table* createTable(){
        return new ChineseTable;
    }
};
class AmericanFactory:public AbstractFactory{
public:
    virtual Chair* creatChair(){
        return new AmericanChair;
    }
    virtual Table* createTable(){
        return new AmericanTable;
    }
};

class Client{
private:
    AbstractFactory* m_factory;
    Chair* chair;
    Table* table;
public:
    Client(AbstractFactory* factory){
        m_factory=factory;
        buyFurniture();
    }
    void dosome(){
        chair->sitdown();
        table->up();
    }
    void setStyle(AbstractFactory* factory){
        m_factory=factory;
        buyFurniture();
    }
    void buyFurniture(){
        chair=m_factory->creatChair();
        table=m_factory->createTable();
    }
    ~Client(){
        delete chair;
        delete table;
    }
};
int main() {
    ChineseFactory f;
    Client c(&f);
    c.dosome();

    return 0;
}
